package Controlador;

import java.awt.event.KeyEvent;

import ar.uba.fi.algo3.titiritero.KeyPressedObservador;

import modelo.Vector;
import modelo.tanque.AlgoTank;

public class EscuchadorKeyPress implements KeyPressedObservador {
	
	private AlgoTank algoTank;
	
	public EscuchadorKeyPress(AlgoTank algoTank){
		this.algoTank = algoTank;
	}
	public void keyPressed(KeyEvent e) {
	  	switch (e.getKeyCode()) {
		  	  case KeyEvent.VK_UP : algoTank.setDireccion(new Vector (0,1));break;
		  	  case KeyEvent.VK_LEFT : algoTank.setDireccion(new Vector(-1,0)); break;
			  case KeyEvent.VK_RIGHT : algoTank.setDireccion(new Vector(1,0)); break;
			  case KeyEvent.VK_DOWN : algoTank.setDireccion(new Vector(0,-1));break;
			  case KeyEvent.VK_SPACE : if(Math.random() < algoTank.getVelocidadDis()){algoTank.disparar();break;
			  }
			  
	  	}
	  
	}
	public void keyReleased(KeyEvent e) {
	   	switch (e.getKeyCode()) {
	   		case KeyEvent.VK_UP : algoTank.setDireccion(new Vector (0,0));break;
	   		case KeyEvent.VK_LEFT : algoTank.setDireccion(new Vector(0,0)); break;
	   		case KeyEvent.VK_RIGHT : algoTank.setDireccion(new Vector(0,0)); break;
	   		case KeyEvent.VK_DOWN : algoTank.setDireccion(new Vector(0,0));break;
	   //	case KeyEvent.VK_SPACE : algoTank.disparar();break;
	   	}
	   	
	  }



}
